package offer;

public class Solution25 {
    public boolean isSubStructure(TreeNode A, TreeNode B) {
        if (A == null || B == null) {
            return false;
        }
        return traveller(A, B) || isSubStructure(A.left, B) || isSubStructure(A.right, B);
    }

    //判断b是否是a的子结构，且b在a中的根结点就是a，且b为空也符合
    private boolean traveller(TreeNode a, TreeNode b) {
        if (b == null) {
            return true;
        }
        if (a == null) {
            return false;
        }
        if (a.val != b.val) {
            return false;
        }
        return traveller(a.left, b.left) && traveller(a.right, b.right);
    }
}
